package com.aiju.cash.ui.multiple_shops.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiju.cash.R;
import com.aiju.bean.ShopClerk;
import com.aiju.utils.Util;

import java.util.List;

/**
 * @author: 佐为
 * @date: 2017-06-13 15:43
 * @version: V1.0
 * @Description: 店员
 */
public class ShopClerkAdapter extends BaseAdapter {

    private Context mContext;

    private List<ShopClerk> shopClerks;

    public ShopClerkAdapter(Context mContext, List<ShopClerk> shopClerks) {
        this.mContext = mContext;
        this.shopClerks = shopClerks;
    }

    @Override
    public int getCount() {
        return shopClerks.size();
    }

    @Override
    public Object getItem(int position) {
        return shopClerks.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rootView = LayoutInflater.from(mContext).inflate(R.layout.item_shop_clerk, null);

        ImageView tagImageView = (ImageView) rootView.findViewById(R.id.iv_clerk_tag);
        TextView stateTextView = (TextView) rootView.findViewById(R.id.tv_clerk_state);
        TextView nameTextView = (TextView) rootView.findViewById(R.id.tv_clerk_name);
        TextView idTextView = (TextView) rootView.findViewById(R.id.tv_clerk_id);

        ShopClerk shopClerk = shopClerks.get(position);
        nameTextView.setText(shopClerk.getUserName());
        idTextView.setText(shopClerk.getPhone());
        if (shopClerk.getRole().equals("2")) {
            tagImageView.setImageResource(R.mipmap.ic_dianyuan);
        } else if (shopClerk.getRole().equals("1")) {
            tagImageView.setImageResource(R.mipmap.ic_dianzhang);
        } else {
            tagImageView.setImageResource(R.mipmap.zong_dianzhagn);

        }
        if (shopClerk.getIsActivate().equals("1")) {
            stateTextView.setTextColor(Util.getColor(R.color.app_display_color));
            stateTextView.setText("已激活");
        } else {
            stateTextView.setTextColor(Util.getColor(R.color.color_999999));
            stateTextView.setText("未激活");
        }
        return rootView;
    }
}
